# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the PreferredEmail Bugzilla Extension.
#
# The Initial Developer of the Original Code is IBM LTC
# Portions created by the Initial Developer are Copyright (C) 2010 the
# Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Tiago Rodrigues de Mello <timello@linux.vnet.ibm.com>

package Bugzilla::Extension::PreferredEmail::Auth::Verify::LDAP;
use strict;
use base qw(Bugzilla::Auth::Verify::LDAP);
use Bugzilla::Constants;

use constant user_can_create_account => 0;

sub can_change_password {
    my ($self) = @_;
    return 0;
}

sub check_credentials {
    my ($self, $params) = @_;
    $params = $self->SUPER::check_credentials($params);
    # Avoids the preferred email overwriting after logging
    # via LDAP.
    my ($preferred_email) = Bugzilla->dbh->selectrow_array(
        'SELECT extern_id FROM profiles WHERE login_name = ?', undef,
        $params->{bz_username});
    $params->{extern_id} = $preferred_email;
    return $params;
}

1;
